package cn.xmstore.dao;

import cn.xmstore.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author： Aeolia
 * @Description： TODO 用户DAO层接口
 * @Date： 2021/8/20 14:00
 */
@Repository
public interface UserDao {

    User findAll();

    @Select("select * from user where id=#{id}")
    User findById(int id);

    @Select("select * from user where phoneNum=#{phoneNum}")
    List<User> findByPhoneNum(@Param("phoneNum") String phoneNum);

    List<User> findByEmail();

    /**
     * 根据小米id和密码查询
     * @param id
     * @param password
     * @return
     */
    @Select("select * from user where id=#{id} and password=#{password}")
    User loginById(@Param("id") int id, @Param("password") String password);

    /**
     * 根据手机号和密码查询
     * @param phoneNum
     * @param password
     * @return
     */
    @Select("select * from user where phoneNum=#{phoneNum} and password=#{password}")
    User loginByPhoneNum(@Param("phoneNum") String phoneNum, @Param("password") String password);

    /**
     * 根据邮箱和密码查询
     * @param email
     * @param password
     * @return
     */
    @Select("select * from user where email=#{email} and password=#{password}")
    User loginByEmail(@Param("email") String email, @Param("password") String password);

    @Insert("insert into user(phoneNum) values(#{phoneNum})")
    void addUserByPhoneNum(@Param("phoneNum") String phoneNum);

}
